﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using OreSystem.Common;
namespace MainFrom
{
    public partial class BackDataForm : Form
    {
        public BackDataForm()
        {
            InitializeComponent();
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtBackPath.Text = fbd.SelectedPath;
            }
        }

        private void BackDataForm_Load(object sender, EventArgs e)
        {
            txtBackName.Text = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + DateTime.Now.Millisecond.ToString() + ".bak"; ;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(txtBackPath.Text))
            {
                MessageBox.Show("备份目录不存在");
                return;
            }
           string bakFile = Path.Combine(txtBackPath.Text,txtBackName.Text);
            //            string sqlBackDatabase = string.Format(@"BACKUP DATABASE OreSystemData
            //  TO DISK = '{0}' 
            //  WITH init;", bakFile);
            string DataBaseName = "OreSystemData";
            try
            {
                ToolSql.BackDataBase(DataBaseName, bakFile);
                MessageBox.Show("备份成功");
                Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }
    }
}
